import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;


class MainMenu extends JFrame implements ActionListener
{	
	private static MainMenu mm=null;
	
	//Constructor + GUI Design
	JButton  btnCreateBatch, btnAddCourse, btnAddStudent, btnEnrolStudnet, btnUpdateSutudentMarks, btnViewResultSheet,btnCalculateGPA, btnExit;		
	JLabel lblHeading;
	
	private MainMenu()
	{	
		
		//Outer Panel
		JPanel screenMain= (JPanel)getContentPane( );
		screenMain.setLayout( new BorderLayout() );		
		screenMain.setBorder(new EmptyBorder(10, 10, 10, 10)); 
		//
		
		//Inner Panel
		JPanel screenSub=new JPanel( );
		screenSub.setLayout( new GridLayout( 4,0,8,8 ));		
		//

		//Heading
		lblHeading=new JLabel(ProgramUitl.HEADNING_TEXT);
		Font fontHeading=new Font(ProgramUitl.FONT_NAME,
									ProgramUitl.HEADING_FONT_STLYE,
									ProgramUitl.HEADING_FONT_SIZE);
		lblHeading.setFont(fontHeading);
		screenMain.add("North",lblHeading);		
		//
		
		//Buttons					
		btnCreateBatch=new JButton(ProgramUitl.ADD_BATCH_TEXT);
		btnAddCourse=new JButton(ProgramUitl.ADD_COURSE_TEXT);
		btnAddStudent=new JButton(ProgramUitl.ADD_STUDENT_TEXT);
		btnEnrolStudnet=new JButton(ProgramUitl.ENROLE_STUDENT_TEXT);
		btnUpdateSutudentMarks=new JButton(ProgramUitl.UPDATE_STUDENT_MARKS_TEXT);
		btnViewResultSheet=new JButton(ProgramUitl.VIEW_RESULT_SHEET_TEXT);
		btnCalculateGPA=new JButton(ProgramUitl.CALCULATE_GPA_TEXT);
		btnExit=new JButton(ProgramUitl.EXIT_TEXT,ProgramUitl.getButtonIcon(ProgramUitl.ICON_TYPE.ERROR));
		
		btnCreateBatch.addActionListener(this);
		btnAddCourse.addActionListener(this);
		btnAddStudent.addActionListener(this);	
		btnEnrolStudnet.addActionListener(this);	
		btnUpdateSutudentMarks.addActionListener(this);	
		btnViewResultSheet.addActionListener(this);	
		btnCalculateGPA.addActionListener(this);		
		btnExit.addActionListener(this);

	
		screenSub.add(btnCreateBatch);
		screenSub.add(btnAddCourse);
		screenSub.add(btnAddStudent);
		screenSub.add(btnEnrolStudnet);
		screenSub.add(btnUpdateSutudentMarks);
		screenSub.add(btnCalculateGPA);		
		screenSub.add(btnViewResultSheet);		
		screenSub.add(btnExit);
		//
		
		//Inner panel added to Outer Panel 
		screenMain.add("Center",screenSub);
		//
		
		//Frame Settings
		setSize(ProgramUitl.SCREEN_WIDTH,ProgramUitl.SCREEN_HEIGHT);
		setLocation(ProgramUitl.SCREEN_LOCATION_TOP,ProgramUitl.SCREEN_LOCATION_LEFT);
		setLocationRelativeTo(null);
		setTitle(ProgramUitl.HEADNING_TEXT);		
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);		
		setUndecorated(true);		
		setVisible(true);
		
		
		validate();
		//
	}
	//
	
	//Events
	public void actionPerformed(ActionEvent ae)
	{
		if(ae.getSource().equals(btnExit))
		{
			exit();
		}
		else if(ae.getSource().equals(btnAddStudent))
		{
			StudentOperation.getInstance();
		}
		else if(ae.getSource().equals(btnAddCourse))
		{
			CourseOperation.getInstance();
		}		
		else if(ae.getSource().equals(btnEnrolStudnet))
		{
			EnrollOperation.getInstance();
		}
		else if(ae.getSource().equals(btnUpdateSutudentMarks))
		{
			MarksOperations.getInstance();
		}
		else if(ae.getSource().equals(btnCreateBatch))
		{
			BatchOperation.getInstance();
		}		
		else if(ae.getSource().equals(btnCalculateGPA))
		{
			GPAOperations.getInstance();
		}
		else if(ae.getSource().equals(btnViewResultSheet))
		{
			ResultSheetOperation.getInstance();
		}
	}	
	//
	
	//Methods
	void exit() 
	{ 		
		int confirmed = JOptionPane.showConfirmDialog(null, 
				ProgramUitl.EXIT_PRORAM_MSG, ProgramUitl.HEADNING_TEXT, 
				JOptionPane.YES_NO_OPTION); 
				
		if (confirmed == JOptionPane.YES_OPTION) 
		{                             		
				System.exit(0);
		} 
	}
	//
	
	//Singleton Pattern for ensure only one instance is created.
	public static MainMenu getInstance()
	{
		if(mm==null){
			mm=new MainMenu();
		}
		return mm;
	}
	//
	
}